package adv7;

import java.util.HashMap;
import java.util.Map;

public class SuperMarket {
    private String name,address;
    Map<Integer,Customer> customers=new HashMap<>();
    public boolean add(Integer integer,Customer customer){
        if (customers.containsKey(integer)){
            System.out.println("会员卡号重复");
            return false;
        }
        customers.put(integer,customer);
        return true;
    }

    public void show(){
        System.out.println("顾客详细信息：\n");
        for(Customer value:customers.values()){
            System.out.println("会员号："+value.getNo()+" 姓名:"+value.getName()+" 电话:"+value.getPhone()+" 积分:"+value.getJifen());
        }
    }

    public boolean increaseJifen(Integer integer,int i){
        if(customers.containsKey(integer)){
            Customer c=customers.get(integer);
            c.setJifen(c.getJifen()+i);
            return true;
        }
        return false;
    }

    public boolean Swap(Integer integer,int choose){
        if(customers.containsKey(integer)){
            Customer c=customers.get(integer);
            switch (choose){
                case 1:if (c.getJifen()>=100){
                    c.setJifen(c.getJifen()-100);
                    System.out.println("兑换成功，获餐巾纸一包");
                    return true;
                }
                    System.out.println("积分不足，兑换失败");
                    return false;
                case 2:if (c.getJifen()>=500){
                    c.setJifen(c.getJifen()-500);
                    System.out.println("兑换成功，获剃须刀一把");
                    return true;
                }
                    System.out.println("积分不足，兑换失败");
                    return false;
                case 3:if (c.getJifen()>=1000){
                    c.setJifen(c.getJifen()-1000);
                    System.out.println("兑换成功，获餐巾纸一包");
                    return true;
                }
                    System.out.println("积分不足，兑换失败");
                    return false;
                default:
                    System.out.println("输入错误");
            }

        }
        System.out.println("查无此人，兑换失败");
        return false;
    }

    public SuperMarket(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
